package com.taiji.controller;

import com.taiji.domain.CommonResult;
import com.taiji.domain.Payment;
import com.taiji.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
public class PayController {
    @Resource
    private PaymentService service;
    @PostMapping(value = "/payment/create")
    public CommonResult create(@RequestBody Payment payment){
        int res = service.create(payment);
        log.info("*****插入结果："+res);
        if (res>0){
            return new CommonResult(200,"插入数据库成功",res);
        }else {
            return new CommonResult(400,"插入数据失败",null);
        }
    }

    @Value("${server.port}")
    private String serverPort;

    @GetMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        Payment payment = service.getPaymentById(id);
        log.info("*****查询结果："+payment);
        if (payment!=null){
            return new CommonResult(200,"查询成功8001"+serverPort,payment);
        }else {
            return new CommonResult(400,"没有查找到对应的数据,ID="+serverPort+id,null);
        }
    }
}
